package cn.edu.ctbu.studentmanage.service.impl;

import cn.edu.ctbu.studentmanage.domain.Course;
import cn.edu.ctbu.studentmanage.domain.Student;
import cn.edu.ctbu.studentmanage.repository.CourseRepository;
import cn.edu.ctbu.studentmanage.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseImplService  implements CourseService {
    @Autowired
    private CourseRepository courseRepository;

    /**
     * 查找所有课程
     * @return
     */
    public List<Course> findAll(){

        return courseRepository.findAll();
    }

    /**
     * 分页
     * @param pageable
     * @return
     */
    public Page<Course> findAll(Pageable pageable) {

        return courseRepository.findAll(pageable);
    }
    /**
     * 分页加动态查询
     * @param courseExample
     * @param pageable
     * @return
     */
    public Page<Course> findAll(Example<Course> courseExample, Pageable pageable){
        return courseRepository.findAll(courseExample,pageable);
    }
    /**
     * 根据课程序号获取课程
     * @param cid
     * @return
     */
    public Course getByCid(Integer cid){

        return courseRepository.findById(cid).orElse(null);
    }
    /**
     * 更新课程信息
     * @param course
     */
    public void update(Course course){
        courseRepository.save(course);
    }
    /**
     * 根据id删除课程
     * @param cid
     */
    public void delete(Integer cid){
        courseRepository.deleteById(cid);
    }
    /**
     * 插入新课程
     * @param course
     */
    public void Insert(Course course){
        courseRepository.save(course);
    }

}
